/*
 * Copyright 2011 Clean GWT
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleanform.gwt.chinesechess.shared.model;

import com.cleanform.gwt.reflect.client.Reflectable;

/**
 * The chess move.
 * 
 * @author Jess
 * @version 1.0
 * @since 1.0
 */
public class ChessMove implements Reflectable {

	private int sx;

	private int sy;

	private int tx;

	private int ty;

	private int source;
	private int target;

	public ChessMove() {
	}

	public ChessMove(int sx, int sy, int tx, int ty) {
		this.setSx(sx);
		this.setSy(sy);
		this.setTx(tx);
		this.setTy(ty);
	}

	public ChessMove(int sx, int sy, int tx, int ty, int source, int target) {
		this.setSx(sx);
		this.setSy(sy);
		this.setTx(tx);
		this.setTy(ty);
		this.setSource(source);
		this.setTarget(target);
	}

//	public ChessMove(SimpleObject object) {
//		sx = object.getInt("sx");
//		sy = object.getInt("sy");
//		tx = object.getInt("tx");
//		ty = object.getInt("ty");
//		source = object.getInt("source");
//		target = object.getInt("target");
//	}

	public boolean checkCriticalMove() {
		return getTarget() == Chess.KING || getTarget() == -Chess.KING;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ChessMove other = (ChessMove) obj;
		if (getTx() != other.getTx()) {
			return false;
		}
		if (getTy() != other.getTy()) {
			return false;
		}
		if (getSx() != other.getSx()) {
			return false;
		}
		if (getSy() != other.getSy()) {
			return false;
		}
		return true;
	}


	/**
	 * @return the source
	 */
	public int getSource() {
		return source;
	}

	/**
	 * @return the sx
	 */
	public int getSx() {
		return sx;
	}


	/**
	 * @return the sy
	 */
	public int getSy() {
		return sy;
	}

	/**
	 * @return the target
	 */
	public int getTarget() {
		return target;
	}

	/**
	 * @return the tx
	 */
	public int getTx() {
		return tx;
	}

	/**
	 * @return the ty
	 */
	public int getTy() {
		return ty;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + getSx();
		result = prime * result + getSy();
		result = prime * result + getTx();
		result = prime * result + getTy();
		return result;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(int source) {
		this.source = source;
	}

	/**
	 * @param sx the sx to set
	 */
	public void setSx(int sx) {
		this.sx = sx;
	}

	/**
	 * @param sy the sy to set
	 */
	public void setSy(int sy) {
		this.sy = sy;
	}

	/**
	 * @param target the target to set
	 */
	public void setTarget(int target) {
		this.target = target;
	}

	/**
	 * @param tx the tx to set
	 */
	public void setTx(int tx) {
		this.tx = tx;
	}

	/**
	 * @param ty the ty to set
	 */
	public void setTy(int ty) {
		this.ty = ty;
	}

	@Override
	public String toString() {
		return "ChessMove [sx=" + getSx() + ", sy=" + getSy() + ", tx=" + getTx() + ", ty=" + getTy() + ", source=" + getSource() + ", target="
				+ getTarget() + "]";
	}

}
